package com.woody.aggregate.application.service.messagebox.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woody.aggregate.application.service.messagebox.IMessageboxConfigService;
import com.woody.aggregate.infrastructure.messagebox.entity.MessageboxConfig;
import com.woody.aggregate.infrastructure.messagebox.mapper.MessageboxConfigMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woody.aggregate.infrastructure.messagebox.wrapmodel.MessageboxListQuery;
import com.woody.aggregate.messagebox.dto.MessageboxAddDTO;
import com.woody.aggregate.messagebox.dto.MessageboxEditDTO;
import com.woody.common.sercurity.interceptor.UserInfoContext;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 弹框配置表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-03-19
 */
@Service
public class MessageboxConfigServiceImpl extends ServiceImpl<MessageboxConfigMapper, MessageboxConfig> implements IMessageboxConfigService {

    @Override
    public Page<MessageboxConfig> getListByDto(Page page,MessageboxListQuery query) {

        return baseMapper.getListByDto(page,query);
    }

    @Override
    public void updateByDto(MessageboxConfig messageboxConfig, MessageboxEditDTO dto) {
        messageboxConfig.setTitle(dto.getTitle());
        messageboxConfig.setApplication(dto.getApplication());
        messageboxConfig.setPictureUrl(dto.getPictureUrl());
        messageboxConfig.setMessageboxTemplate(dto.getMessageboxTemplate());
        messageboxConfig.setPushRuleId(dto.getPushRuleId());
        messageboxConfig.setUpdateTime(new Date());
        messageboxConfig.setUpdateUserId(UserInfoContext.get().getUserId());
        messageboxConfig.setUpdateUserName(UserInfoContext.get().getUsername());
        baseMapper.updateById(messageboxConfig);
    }

    @Override
    public MessageboxConfig add(MessageboxAddDTO dto) {
        MessageboxConfig messageboxConfig = new MessageboxConfig();
        BeanUtils.copyProperties(dto, messageboxConfig);
        messageboxConfig.setStatus(0);
        messageboxConfig.setDel(0l);
        messageboxConfig.setCreateUserId(UserInfoContext.get().getUserId());
        messageboxConfig.setUpdateUserId(UserInfoContext.get().getUserId());
        messageboxConfig.setCreateUserName(UserInfoContext.get().getUsername());
        messageboxConfig.setUpdateUserName(UserInfoContext.get().getUsername());
        Date now = new Date();
        messageboxConfig.setCreateTime(now);
        messageboxConfig.setUpdateTime(now);
        baseMapper.insert(messageboxConfig);
        return messageboxConfig;
    }
}
